﻿#include "DigOutZombie.h"
#include "../../../Shared/ServerPackets.h"
#include "../SpellObject.h"

using namespace Server::MirDatabase;
namespace S = ServerPackets;

namespace Server::MirObjects::Monsters
{

    bool DigOutZombie::getCanAttack() const
    {
        return Visible && MonsterObject::getCanAttack();
    }

    bool DigOutZombie::getCanMove() const
    {
        return Visible && MonsterObject::getCanMove();
    }

    bool DigOutZombie::getBlocking() const
    {
        return Visible && MonsterObject::getBlocking();
    }

    DigOutZombie::DigOutZombie(MonsterInfo *info) : MonsterObject(info)
    {
        Visible = false;
    }

    void DigOutZombie::ProcessAI()
    {
        if (!Dead && getEnvir()->getTime() > VisibleTime)
        {
            VisibleTime = getEnvir()->getTime() + 2000;

            bool visible = FindNearby(3);

            if (!Visible && visible)
            {
                Visible = true;
                CellTime = getEnvir()->getTime() + 500;
                Broadcast(GetInfo());
                S::ObjectShow *tempVar = new S::ObjectShow();
                tempVar->ObjectID = ObjectID;
                Broadcast(tempVar);
                ActionTime = getEnvir()->getTime() + 2000;
                DigOutTime = getEnvir()->getTime();
                DigOutLocation = getCurrentLocation();
                DigOutDirection = getDirection();

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar' statement was not added since tempVar was passed to a method or constructor. Handle memory management manually.
            }
        }

        if (Visible && getEnvir()->getTime() > DigOutTime + 1000 && !DoneDigOut)
        {
            SpellObject *ob = new SpellObject();
            ob->Spell = Spell::DigOutZombie;
            ob->Value = 1;
            ob->ExpireTime = getEnvir()->getTime() + (5 * 60 * 1000);
            ob->TickSpeed = 2000;
            ob->Caster = nullptr;
            ob->setCurrentLocation(DigOutLocation);
            ob->setCurrentMap(this->getCurrentMap());
            ob->setDirection(DigOutDirection);
            getCurrentMap()->AddObject(ob);
            ob->Spawned();
            DoneDigOut = true;

//C# TO C++ CONVERTER TODO TASK: A 'delete ob' statement was not added since ob was passed to a method or constructor. Handle memory management manually.
        }

        MonsterObject::ProcessAI();
    }

    bool DigOutZombie::Walk(MirDirection dir)
    {
        return Visible && MonsterObject::Walk(dir);
    }

    bool DigOutZombie::IsAttackTarget(MonsterObject *attacker)
    {
        return Visible && MonsterObject::IsAttackTarget(attacker);
    }

    bool DigOutZombie::IsAttackTarget(PlayerObject *attacker)
    {
        return Visible && MonsterObject::IsAttackTarget(attacker);
    }

    void DigOutZombie::ProcessSearch()
    {
        if (Visible)
        {
            MonsterObject::ProcessSearch();
        }
    }

    Packet *DigOutZombie::GetInfo()
    {
        return !Visible ? nullptr : MonsterObject::GetInfo();
    }
}
